package cn.lg.soar.message.service.impl;

import cn.lg.soar.common.util.current.CurrentProxy;
import cn.lg.soar.message.api.enums.MailSendStatusEnum;
import cn.lg.soar.message.entity.MailLog;
import cn.lg.soar.message.mapper.MailLogMapper;
import cn.lg.soar.message.service.IMailLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDateTime;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class MailLogServiceImpl extends ServiceImpl<MailLogMapper, MailLog> implements IMailLogService, CurrentProxy<IMailLogService> {

    @Override
    public boolean successLog(String subject, String content, String... tos) {
        MailLog mailLog = new MailLog();
        mailLog.setSubject(content);
        mailLog.setContent(content);
        mailLog.setTos(tos);
        mailLog.setTime(LocalDateTime.now());

        mailLog.setStatus(MailSendStatusEnum.SUCCESS);
        try {
            return save(mailLog);
        } catch (RuntimeException e) {
            return false;
        }
    }

    @Override
    public boolean failLog(String subject, String content, String... tos) {
        MailLog mailLog = new MailLog();
        mailLog.setSubject(content);
        mailLog.setContent(content);
        mailLog.setTos(tos);
        mailLog.setTime(LocalDateTime.now());

        mailLog.setStatus(MailSendStatusEnum.FAIL);
        try {
            return save(mailLog);
        } catch (RuntimeException e) {
            return false;
        }
    }

}
